<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button>发起请求</button>   
     <h1 style="display:none">我是页面</h1>
    
    <!-- <script src="./03.Promise基本用法.js"></script> -->
    <script src="./Promise封装请求方式.js"></script>

    <script>
 
        const btn = document.querySelector('button')
        const h1=document.querySelector('h1')
        btn.addEventListener('click', async function () {
            const res = await harryAjax({ method: 'GET', url: 'http://ajax-base-api-t.itheima.net/api/getbooks' })
            console.log(res);
        })
        Promise.all([
            harryAjax({ method: 'GET', url: 'http://ajax-base-api-t.itheima.net/api/getbooks' }),
            harryAjax({ method: 'POST', data: { bookname: 'promise.all', author: '35', publisher: 'heima' }, url: 'http://ajax-base-api-t.itheima.net/api/addbook' })
        ]).then(res => {
            console.log(res);
            h1.style.display = 'block'
        }).catch(err => {
            console.log(err);   
            h1.style.display = 'block'
            h1.innerHTML = err
        })

        
    </script>
</body>

</html>